﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.Reflection;
using System.Net;

namespace DbSharp.Utils.ComputerDetect
{ 
    public class FriendlyHardwareId
    {
        public static string GetHostName()
        {
            string result = Dns.GetHostEntry(System.Net.Dns.GetHostName()).HostName;
            return result.ToLower();
        }

        public static bool TryGetHardwareId(out string hardwareId)
        {
            hardwareId = string.Empty;
            bool result = false;
            try
            {
                //get full qualified host name 
                hardwareId = GetHostName(); ;
                result = true;
            }
            catch
            {
                result = false;
            }

            return result;
        }

        public static bool TryGetHardwareId(out byte[] utf8ByteUniqueId)
        {
            utf8ByteUniqueId = null;
            string uniqueId = string.Empty;
            var result = TryGetHardwareId(out uniqueId);
            utf8ByteUniqueId = System.Text.Encoding.UTF8.GetBytes(uniqueId);
            return result;
        }
    }
}
